/* Replication file for Banda and Carsey 2015, "Two-stage elections, strategic 
candidates, and campaign agendas"

Note from Kevin Banda: There are a few small errors in the replication data vs
that which is presented in the paper. I put together this replication file in 2017,
but did much of the empirical work in 2013. So my memory is a bit foggy at this
point. As I recall, at some point I found and fixed a few very small coding errors.
It looks as if I fixed most of the reported results throughout the paper, but there
remain a small number of inconsistencies between what you will replicate here and
what is reported in Tables 1 and 2. I suspect that I forgot to update the tables.
These mistakes center on the variables for the winner of contested primary
elections advertising agendas in contests in which only one primary is contested.
As you will see, these errors don't change the substance of the findings. This
stuff mostly looks like rounding errors, though that's not what happened.

My mistake; I wasn't adequately careful. Do note that if you want to recreate
Figure 1 with the results that match the corrected results from this replication,
you will need to substitute slightly different values into the R script file.
 
*/

* Table 1: static descriptives

* Primary election summary
use "Table1.dta", clear
* One contested primary
sum sponsorown sponsoropp primaryown primaryopp generalown generalopp if both==0
* Two contested primaries
sum demownper otherdemownper demoppper otherdemoppper repownper otherrepownper ///
	repoppper otherrepoppper if both==1
	
* General election summary
use "Table1b.dta", clear
* One contested primary
sum sponsorown sponsoropp generalown generalopp if both==0
* Two contested primaries
sum demownper demoppper repownper repoppper if both==1



* Tables 2 and 3: dynamic models
use "dynamic replication.dta", clear

tsset panelvar week

* Table 2
sureg (d.sponsordemc l.sponsordemc d.primarydemc l.primarydemc d.generaldemc l.generaldemc demwin governor d02 d03 d04 d08) ///
(d.primarydemc l.primarydemc d.sponsordemc l.sponsordemc d.generaldemc l.generaldemc demwin governor d02 d03 d04 d08) ///
(d.generaldemc l.generaldemc d.sponsordemc l.sponsordemc d.primarydemc l.primarydemc demgen governor d02 d03 d04 d08) ///
(d.sponsorrepc l.sponsorrepc d.primaryrepc l.primaryrepc d.generalrepc l.generalrepc demwin governor d02 d03 d04 d08) ///
(d.primaryrepc l.primaryrepc d.sponsorrepc l.sponsorrepc d.generalrepc l.generalrepc demwin governor d02 d03 d04 d08) ///
(d.generalrepc l.generalrepc d.sponsorrepc l.sponsorrepc d.primaryrepc l.primaryrepc demgen governor d02 d03 d04 d08) if both==0, cor
estat ic

* Bewley transformation to get the long run multipliers

* Step 1
sureg (d.sponsordemc l.sponsordemc d.primarydemc primarydemc d.generaldemc generaldemc demwin governor d02 d03 d04 d08) ///
(d.primarydemc l.primarydemc d.sponsordemc sponsordemc d.generaldemc generaldemc demwin governor d02 d03 d04 d08) ///
(d.generaldemc l.generaldemc d.sponsordemc sponsordemc d.primarydemc primarydemc demgen governor d02 d03 d04 d08) ///
(d.sponsorrepc l.sponsorrepc d.primaryrepc primaryrepc d.generalrepc generalrepc demwin governor d02 d03 d04 d08) ///
(d.primaryrepc l.primaryrepc d.sponsorrepc sponsorrepc d.generalrepc generalrepc demwin governor d02 d03 d04 d08) ///
(d.generalrepc l.generalrepc d.sponsorrepc sponsorrepc d.primaryrepc primaryrepc demgen governor d02 d03 d04 d08) if both==0
predict sponsordemfitc, xb equation(#1)
predict primarydemfitc, xb equation(#2)
predict generaldemfitc, xb equation(#3)
predict sponsorrepfitc, xb equation(#4)
predict primaryrepfitc, xb equation(#5)
predict generalrepfitc, xb equation(#6)

* Step 2
	* LRMs are coefs on the variables marked "--" in the output
sureg (sponsordemc sponsordemfitc d.primarydemc primarydemc d.generaldemc generaldemc demwin governor d02 d03 d04 d08) ///
(primarydemc primarydemfitc d.sponsordemc sponsordemc d.generaldemc generaldemc demwin governor d02 d03 d04 d08) ///
(generaldemc generaldemfitc d.sponsordemc sponsordemc d.primarydemc primarydemc demgen governor d02 d03 d04 d08) ///
(sponsorrepc sponsorrepfitc d.primaryrepc primaryrepc d.generalrepc generalrepc demwin governor d02 d03 d04 d08) ///
(primaryrepc primaryrepfitc d.sponsorrepc sponsorrepc d.generalrepc generalrepc demwin governor d02 d03 d04 d08) ///
(generalrepc generalrepfitc d.sponsorrepc sponsorrepc d.primaryrepc primaryrepc demgen governor d02 d03 d04 d08) if both==0

* Tests of equivalency among the LRMs within equations
test [sponsordemc]primarydemc = [sponsordemc]generaldemc
test [primarydemc]sponsordemc = [primarydemc]generaldemc
test [generaldemc]sponsordemc = [generaldemc]primarydemc
test [sponsorrepc]primaryrepc = [sponsorrepc]generalrepc
test [primaryrepc]sponsorrepc = [primaryrepc]generalrepc
test [generalrepc]sponsorrepc = [generalrepc]primaryrepc




* Table 3
sureg (d.demown l.demown d.otherdemown l.otherdemown d.repopp l.repopp d.otherrepopp l.otherrepopp governor d02 d04) ///
(d.otherdemown l.otherdemown d.demown l.demown d.repopp l.repopp d.otherrepopp l.otherrepopp governor d02 d04) ///
(d.repopp l.repopp d.otherrepopp l.otherrepopp d.demown l.demown d.otherdemown l.otherdemown governor d02 d04) ///
(d.otherrepopp l.otherrepopp d.repopp l.repopp d.demown l.demown d.otherdemown l.otherdemown governor d02 d04) ///
(d.demopp l.demopp d.otherdemopp l.otherdemopp d.repown l.repown d.otherrepown l.otherrepown governor d02 d04) ///
(d.otherdemopp l.otherdemopp d.demopp l.demopp d.repown l.repown d.otherrepown l.otherrepown governor d02 d04) ///
(d.repown l.repown d.otherrepown l.otherrepown d.demopp l.demopp d.otherdemopp l.otherdemopp governor d02 d04) ///
(d.otherrepown l.otherrepown d.repown l.repown d.demopp l.demopp d.otherdemopp l.otherdemopp governor d02 d04) if both==1,cor
estat ic

* Bewley transformation to get the long run multipliers

* Step 1
sureg (d.demown l.demown d.otherdemown otherdemown d.repopp repopp d.otherrepopp otherrepopp governor d02 d04) ///
(d.otherdemown l.otherdemown d.demown demown d.repopp repopp d.otherrepopp otherrepopp governor d02 d04) ///
(d.repopp l.repopp d.otherrepopp otherrepopp d.demown demown d.otherdemown otherdemown governor d02 d04) ///
(d.otherrepopp l.otherrepopp d.repopp repopp d.demown demown d.otherdemown otherdemown governor d02 d04) ///
(d.demopp l.demopp d.otherdemopp otherdemopp d.repown repown d.otherrepown otherrepown governor d02 d04) ///
(d.otherdemopp l.otherdemopp d.demopp demopp d.repown repown d.otherrepown otherrepown governor d02 d04) ///
(d.repown l.repown d.otherrepown otherrepown d.demopp demopp d.otherdemopp otherdemopp governor d02 d04) ///
(d.otherrepown l.otherrepown d.repown repown d.demopp demopp d.otherdemopp otherdemopp governor d02 d04) if both==1
predict demownfitc, xb equation(#1)
predict otherdemownfitc, xb equation(#2)
predict repoppfitc, xb equation(#3)
predict otherrepoppfitc, xb equation(#4)
predict demoppfitc, xb equation(#5)
predict otherdemoppfitc, xb equation(#6)
predict repownfitc, xb equation(#7)
predict otherrepownfitc, xb equation(#8)

* Step 2
	* LRMs are coefs on the variables marked "--" in the output
sureg (demown demownfitc d.otherdemown otherdemown d.repopp repopp d.otherrepopp otherrepopp governor d02 d04) ///
(otherdemown otherdemownfitc d.demown demown d.repopp repopp d.otherrepopp otherrepopp governor d02 d04) ///
(repopp repoppfitc d.otherrepopp otherrepopp d.demown demown d.otherdemown otherdemown governor d02 d04) ///
(otherrepopp otherrepoppfitc d.repopp repopp d.demown demown d.otherdemown otherdemown governor d02 d04) ///
(demopp demoppfitc d.otherdemopp otherdemopp d.repown repown d.otherrepown otherrepown governor d02 d04) ///
(otherdemopp otherdemoppfitc d.demopp demopp d.repown repown d.otherrepown otherrepown governor d02 d04) ///
(repown repownfitc d.otherrepown otherrepown d.demopp demopp d.otherdemopp otherdemopp governor d02 d04) ///
(otherrepown otherrepownfitc d.repown repown d.demopp demopp d.otherdemopp otherdemopp governor d02 d04) if both==1

* Tests of equivalency among the LRMs within equations
test [demown]otherdemown = [demown]repopp
test [demown]otherdemown = [demown]otherrepopp
test [otherdemown]demown = [otherdemown]repopp
test [otherdemown]demown = [otherdemown]otherrepopp
test [repopp]otherrepopp = [repopp]demown
test [repopp]otherrepopp = [repopp]otherdemown
test [otherrepopp]repopp = [otherrepopp]demown
test [otherrepopp]repopp = [otherrepopp]otherdemown
test [demopp]otherdemopp = [demopp]repown
test [demopp]otherdemopp = [demopp]otherrepown
test [otherdemopp]demopp = [otherdemopp]repown
test [otherdemopp]demopp = [otherdemopp]otherrepown
test [repown]otherrepown = [repown]demopp
test [repown]otherrepown = [repown]otherdemopp
test [otherrepown]repown = [otherrepown]demopp
test [otherrepown]repown = [otherrepown]otherdemopp
